package com.chaoyi.service.Impl;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.Part;

import org.springframework.stereotype.Service;

import com.chaoyi.config.WSUploadConfig;
import com.chaoyi.dao.mysql.PortraitPicturesMapper;
import com.chaoyi.model.PortraitPictures;
import com.chaoyi.model.PortraitPicturesSet;
import com.chaoyi.service.PortraitPicturesService;
import com.chaoyi.util.UUIDUtil;
import com.chaoyi.util.oss.ApkOSSConfigure;
import com.chaoyi.util.oss.ApkOSSManageUtil;
import com.chaoyi.util.qiniu.UploadFileQiNiu;

@Service
public class PortraitPicturesServiceImpl implements PortraitPicturesService{
	
	@Resource
	PortraitPicturesMapper portraitPicturesMapper;
	@Override
	public List<PortraitPictures> findList(String offset, String limit,String type) {
		return portraitPicturesMapper.findList(offset,limit,type);
	}
	
	@Override
	public int findCount(String type) {
		return portraitPicturesMapper.findCount(type);
	}
	@Override
	public int addPicturesSave(PortraitPictures entity) {
		return portraitPicturesMapper.addPicturesSave(entity);
	}
	
	@Override
	public String uploadClassifyImg2WSCDN(Part uploadFile) throws IOException, Exception {
		String exten = uploadFile.getSubmittedFileName().substring(uploadFile.getSubmittedFileName().lastIndexOf("."));
		String fileName = UUIDUtil.getUUID() + exten;
//		return ApkOSSManageUtil.uploadFile(new ApkOSSConfigure(), uploadFile, WSUploadConfig.portraitImgUrlPath,
//				fileName);
		return UploadFileQiNiu.uploadFile(uploadFile, WSUploadConfig.portraitImgUrlPath, fileName);
	}
	@Override
	public PortraitPictures findPicturesOne(int id) {
		return portraitPicturesMapper.findPicturesOne(id);
	}
	
	@Override
	public int alertPicturesSave(PortraitPictures entity) {
		return portraitPicturesMapper.alertPicturesSave(entity);
	}
	
	@Override
	public int deletePictures(int id) {
		return portraitPicturesMapper.deletePictures(id);
	}
	
	@Override
	public int deletePicturesSetParentId(int parentId) {
		return portraitPicturesMapper.deletePicturesSetParentId(parentId);
	}
	
	@Override
	public int deletePicturesSetId(int id) {
		return portraitPicturesMapper.deletePicturesSetId(id);
	}

	@Override
	public int addPicturesSetSave(PortraitPicturesSet entity) {
		return portraitPicturesMapper.addPicturesSetSave(entity);
	}

	@Override
	public List<PortraitPicturesSet> picturesSetList(int parentId) {
		return portraitPicturesMapper.picturesSetList(parentId);
	}

	@Override
	public List<PortraitPictures> findListPic(String offset, String limit, String type, String picType) {
		return portraitPicturesMapper.findListPic(offset,limit,type,picType);
	}
	
	

}
